package cn.itcast.itcaststore.web.servlet.manager;

import cn.itcast.itcaststore.domain.Notice;
import cn.itcast.itcaststore.domain.Orders;
import cn.itcast.itcaststore.serive.NoticeService;
import cn.itcast.itcaststore.serive.OrderService;
import cn.itcast.itcaststore.serive.impl.NoticeServiceImpl;
import cn.itcast.itcaststore.serive.impl.OrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;


/**
 *	后台查询所有公告的servlet
 */
@WebServlet("/admin/findNotice")
public class ListNoticeServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        NoticeService noticeService=new NoticeServiceImpl();
        try {
            List<Notice> noticeList=noticeService.findAllNotice();
            req.setAttribute("notices",noticeList);
            req.getRequestDispatcher("/admin/notices/list.jsp").forward(req, resp);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
